/**
 * 
 */


import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.furschina.model.Navigation;

/**
 * @author iday
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/spring-test.xml"})
public class NavigationDaoTestCase {
	@Autowired
	NavigationDao dao;
	private List<Navigation> list = new ArrayList<Navigation>();

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		Navigation root = new Navigation("门户导航");
		dao.create(root);
		list.add(root);
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		dao.deleteAll(list);
		list.clear();
	}

	@Test
	public void testDelete() {
		Navigation root = list.remove(0);
		Navigation leaf = new Navigation("资讯动态", "/home.xhtml", root);
		dao.create(leaf);
		assertTrue(leaf.getId() > 0);
		dao.deleteByPrimaryKey(root.getId());
		assertNull(dao.findByPrimaryKey(leaf.getId()));
	}

}
